/**
 * 
 */
package com.wolfpire.system.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.wolfpire.system.common.Page;
import com.wolfpire.system.common.base.dao.IBaseHibernateDao;
import com.wolfpire.system.common.base.service.impl.BaseHibernateService;
import com.wolfpire.system.dao.AttachmentDao;
import com.wolfpire.system.model.Attachment;
import com.wolfpire.system.service.AttachmentService;

/**
 * @author lihd
 *
 */

@Service("attachmentService")
public class AttachmentServiceImpl extends
		BaseHibernateService<Attachment, Long> implements AttachmentService {
	
	@Resource private AttachmentDao attachmentDao;
	
	public List<Attachment> list(Attachment entity) {
		// TODO Auto-generated method stub
		return null;
	}

	
	public List<Attachment> getByBiz(Long bizId, String attaType) {
		return this.attachmentDao.getByBiz(bizId, attaType);
	}

	
	public List<Attachment> getById(Long[] attId) {
		return this.attachmentDao.getById(attId);
	}

	
	protected IBaseHibernateDao<Attachment, Long> getEntityDao() {
		return this.attachmentDao;
	}

	
	public void del(Long attId) {
		// TODO Auto-generated method stub
		Attachment attachment = this.attachmentDao.get(attId);
		if (null != attachment) {
			attachment.setBizId(0L);
			attachment.setAttaType(StringUtils.EMPTY);
			this.attachmentDao.save(attachment);
		}
	}

	
	public void batchRelateAttachment(Long[] attId, Long bizId, String attaType) {
		if (ArrayUtils.isNotEmpty(attId) && null != bizId) {
			for (Long id : attId) {
				Attachment attament = this.attachmentDao.get(id);
				attament.setBizId(bizId);
				attament.setAttaType(attaType);
				this.attachmentDao.saveOrUpdate(attament);
			}
		}
	}

	
	public Page<Map<String, Object>> setTaskDetailList(Page<Map<String, Object>> page,
			Attachment filterAttachment) {
		/*if (null != filterAttachment) {
			Long taskId = filterAttachment.getBizId();
			FeedBack feedBack = new FeedBack();
			feedBack.setTaskId(taskId);
			List<FeedBack> feedBacks = this.feedBackDao.list(feedBack);
			List<Long> feedBacksId = new ArrayList<Long>();
			for (FeedBack fb : feedBacks) {
				feedBacksId.add(fb.getId());
			}
			return this.attachmentDao.findTaskDetails(page, filterAttachment, taskId, feedBacksId);
		} else {
			return null;
		}*/
		return null;
	}

	
	public Page<Map<String, Object>> setAttachmentsByPiId(
			Page<Map<String, Object>> page, Long projectIndexId, Attachment filterAttachment) {
		return this.attachmentDao.findAttachmentsByPiId(page, projectIndexId, filterAttachment);
	}
	
	public Page<Map<String, Object>> setAttachmentsBySubjectId(
			Page<Map<String, Object>> page, Long subjectId, Long professionId, Attachment filterAttachment) {
		return this.attachmentDao.findAttachmentsBySubjectId(page, subjectId, professionId, filterAttachment);
	}


	public List<Attachment> getByBizAndFileType(Long bizId, String attaType,
			String fileType) {
		return this.attachmentDao.getByBizAndFileType(bizId, attaType, fileType);
	}

}
